<template>
  <Layout>
    <!-- Page Header -->
    <header 
    class="masthead"
    :style="{backgroundImage:`url(http://localhost:1337${general.cover.url})`}"
    >
      <div class="overlay"></div>
      <div class="container">
        <div class="row">
          <div class="col-lg-8 col-md-10 mx-auto">
            <div class="site-heading">
              <h1>{{ general.title }}</h1>
              <span class="subheading">{{ general.sub }}</span>
            </div>
          </div>
        </div>
      </div>
    </header>
    <!-- Main Content -->
    <div class="container">
      <div class="row">
        <div class="col-lg-8 col-md-10 mx-auto">
          <div
            class="post-preview"
            v-for="edge in $page.posts.edges"
            :key="edge.node.id"
          >
            <g-link :to="'/post/'+edge.node.id">
              <h2 class="post-title">
                {{ edge.node.title }}
              </h2>
              <!-- <h3 class="post-subtitle">
                Problems look mighty small from 150 miles up
              </h3> -->
            </g-link>
            <p class="post-meta">
              Posted by
              <a href="#">{{ edge.node.author }}</a>
              on {{ edge.node.created_at | date("MMM DD, YYYY") }}
            </p>
            <p>
              <g-link class="tag-item" :to="`/tag/${tag.id}`" v-for="tag in edge.node.tags" :key="tag.id">{{ tag.title }}</g-link>
            </p>
            <hr />
          </div>
          <!-- Pager -->
          <Pager :info="$page.posts.pageInfo" />
          <!-- <div class="clearfix">
            <a class="btn btn-primary float-right" href="#"
              >Older Posts &rarr;</a
            >
          </div> -->
        </div>
      </div>
    </div>
  </Layout>
</template>
<page-query>
query ($page: Int) {
  posts: allStrapiPost(perPage: 2, page: $page) @paginate {
    pageInfo{
      totalPages
      currentPage
    }
    edges{
      node{
        id
        author
        title
        content
        created_at
        tags{
          id
          title
        }
      }
    }
  }
  general: allStrapiGeneral{
    edges{
      node{
        id
        title
        sub
        cover{
          url
        }
      }
    }
  }
}
</page-query>
<script>
import { Pager } from "gridsome"
export default {
  name: "HomePage",
  metaInfo: {
    title: "Hello, world!",
  },
  components: {
    Pager,
  },
  computed: {
    general() {
      return this.$page.general.edges[0].node
    }
  }
}
</script>

<style>
.container nav a {
  display: inline-block;
  padding: 0 10px;
  border: solid 1px #ddd;
  margin-right: -1px;
}
.container nav a.active {
  background: #0086cc;
  color: #fff;
}
.tag-item{
  font-size: 12px;
  padding: 5px 10px;
  border: solid 1px #0086cc;
  background-color: #b2e4ff;
  color: #0086cc;
  border-radius: 5px;
  text-decoration: none;
  margin-right: 5px;
}
</style>
